﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
using System.Windows.Media;
namespace WPFExcelReport
{
    public partial class TXJVA30
    {

        public TXJVA30()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VVAKDBEZ();
            this.DataContext = MV;
            InitializeComponent();
        }


        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwVAK = dwMaster;
            if (dwMaster == null)
            {
                KEY = "";
                TXTISIND = "";
            }
            else
            {
                KEY = dwMaster["VAKBKOLL"].ToString() + dwMaster["VAKBART"].ToString() + dwMaster["VAKBFARBE"].ToString() + dwMaster["VAKBKUNDNR"].ToString().Trim().PadRight(8);
             }
        }

        public override void LOADBYAUF()
        {          
            base.LOADBYAUF();
            TBMain.Clear();
            if (ORDERNUM.Length < 47)
                return;
            dwData = TBMain.NewRow();
            dwData["VAKBMANDANT"] = app.Mandant;
            dwData["VAKBKOLL"] = ORDERNUM.Substring(0, 5);
            dwData["VAKBART"] = ORDERNUM.Substring(5, 24);
            dwData["VAKBFARBE"] = ORDERNUM.Substring(29, 10);
            dwData["VAKBKUNDNR"] = ORDERNUM.Substring(39, 8);
            SResult = TMV.QVAK06(dwData);
            MergeData(SResult, true);
            if (!IsAuto)
                return;
            #region=========VAFARBEN=========
            DataRow dwVF = VVAFARBEN.Instance.TBMain.NewRow();
            VVAFARBEN.Instance.SetUpNewRow(ref dwVF, null);
            dwVF["VAFKOLL"] = dwMaster["VAKBKOLL"];
            dwVF["VAFART"] = dwMaster["VAKBART"];
            dwVF["VAFFARBE"] = dwMaster["VAKBFARBE"];
            dwVF["VAFBEZ"] = VAFBEZ.Trim().PadRight(20);
            dwVF["VAFFARBGRP"] = CGRP; 
            VVAFARBEN.Instance.UpdateVAFARBEN(dwVF, app.company, 6);
            #endregion
        }
    }
}
